package _interview150;

/**
 * 88. 合并两个有序数组
 */
public class No88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int i1 = 0, i2 = 0;

        int it = 0;
        int[] temp = new int[m + n];

        while (i1 < m && i2 < n) {
            temp[it++] = nums1[i1] < nums2[i2] ? nums1[i1++] : nums2[i2++];
        }
        while (it < m + n) {
            temp[it++] = i1 == m ? nums2[i2++] : nums1[i1++];
        }
        System.arraycopy(temp, 0, nums1, 0, m + n);
    }
}
